package cn.edu.zut.qixiang.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author 86178
 */
@Data
@Component
@ConfigurationProperties(prefix = "realtime.weather")
public class RealTimeWeatherConfig {

    private String topic;
    private String maxwellTopic;
    private String districts;
    private int dataRetentionMinutes = 10;
    private long updateIntervalMs = 60000;
    private MysqlConfig mysql = new MysqlConfig();
    private GenerationConfig generation = new GenerationConfig();
    private MonitoringConfig monitoring = new MonitoringConfig();

    // JDK 8兼容的获取区域列表方法
    public List<String> getDistricts() {
        if (districts == null || districts.trim().isEmpty()) {
            return new ArrayList<>();
        }
        return Arrays.asList(districts.split(","));
    }

    @Data
    public static class MysqlConfig {
        private boolean batchInsert = true;
        private int batchSize = 50;
    }

    @Data
    public static class GenerationConfig {
        private boolean enabled = true;
        private long initialDelayMs = 10000;
    }

    @Data
    public static class MonitoringConfig {
        private boolean enabled = true;
        private long statsIntervalMs = 30000;
    }
}